<!DOCTYPE html>
<html>
<head>
    <title>酒店列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
    <script src="/js/plugins/dialog/dialog.min.js"></script>
    <script src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
</head>
<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
    </div>
</div>
<div class="container">
    <h6 class="module-title text-left">骡窝窝酒店预订</h6>
    <div id="hotels" class="carousel-inner">
        <div class="border commend">
            <form class="form-inline" id="searchForm" action="/hotels" method="post">
                <div class="form-group">
                    <label>酒店名称:</label>
                    <input type="text" class="form-control" name="keyword" name="keyword" placeholder="请输入酒店名称">
                </div>
                <div class="form-group">
                    <label>到店时间:</label>
                    <input type="text" class="form-control" id="beginTime" name="beginTime" width="20%"
                           onclick="WdatePicker()" placeholder="请输入住店时间">
                </div>
                <div class="form-group">
                    <label>离店时间:</label>
                    <input type="text" class="form-control" id="endTime" name="endTime" width="20%"
                           onclick="WdatePicker()" placeholder="请输入离店时间">
                </div>
                <a role="button" id="btn_query" class="btn btn-info searchBtn">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </a>
            </form>
        </div>
    </div>
</div>

<div class="container hotels">
    <h6>酒店列表</h6>
    <div id="allHotels" render-loop="list">
        <div class="row detail">
            <dd>
                <!--动态渲染a标签-->
                <a href="hotelcontent.html" render-key="list.id" render-fun="handle">
                    <img render-src="list.roomUrl">
                    <h6 class="name" render-html="list.name"></h6>
                </a>
            </dd>
        </div>
        <div class="row detail">
            <div class="col">
                <a href="hotelcontent.html?id=1">
                    <span>阿联酋皇宫酒店</span>
                </a>
                <p>
                    <a href="userProfiles.html">
                    </a>
                    <span class="addr">阿联酋</span>
                </p>
            </div>
            <div class="col bigimg">
                <a href="hotelcontent.html?id=1">
                    <img src="/upload/aba61437-23b1-41e8-bada-165b7ccc8722.png">
                </a>
            </div>
        </div>
        <div class="row detail">
            <div class="col">
                <a href="hotelcontent.html?id=2">
                    <span>土耳其玛丹宫廷酒店</span>
                </a>
                <p>
                    <a href="userProfiles.html">
                    </a>
                    <span class="addr">土耳其</span>
                </p>
            </div>
            <div class="col bigimg">
                <a href="hotelcontent.html?id=2">
                    <img src="/upload/aba61437-23b1-41e8-bada-165b7ccc8722.png">
                </a>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    //设置当前页数
    var currentPage = 1;
    //设置总页数
    var pages;
    //设置酒店列表数组
    var hotels;
    // 页面加载完毕执行
    $(function () {
        $(".searchBtn").click(function () {
            var args = {
                "keyword": $("#searchForm input[name='keyword']").val(),
                "beginTime": $("#searchForm input[name='beginTime']").val(),
                "endTime": $("#searchForm input[name='endTime']").val(),
                "currentPage":currentPage,
                "pages":4
            };
            // 页面加载完毕发送请求获取酒店的数据
            $.get("/hotels", args, function (data) {
                console.log(data);
                //保存查询出的酒店
                hotels = data.list;
                //保存当前的总页数
                pages = data.pages;
                //data = ({list: data});
                // 渲染页面数据
                renderValues(data);
            });
            //分页屏幕计算
            function isEnd() {
                return $(window).height() + $(window).scrollTop() >= $(document).height();
            }
            //分页效果,设置一个监听屏幕事件
            $(window).scroll(function () {
                //判断是否到了屏幕的底部
                if (isEnd()){
                    if (currentPage<pages){
                        currentPage++;
                        $.get("/hotels", args, function (data) {
                            $.merge(hotels,data.list);
                            renderValues(data);
                        })
                    }else {
                        // 否则, 提示已到底部
                        $(document).dialog({
                            type: 'notice',
                            infoText: '已到底部',
                            autoClose: 2500,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
                    }
                }
            })
        });

        //渲染
        function renderValues(data){
            $(".hotels").renderValues(data, {
                // 动态渲染 a 标签
                handle: function (ele, value) {
                    ele.href = "/hotelcontent.html?id=" + value;
                }
            });
        }
    })
</script>
</html>